package com.zh.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zh.entity.UpImg;
import com.zh.entity.User;
import com.zh.service.UpImgService;
import com.zh.service.UserService;
import com.zh.util.*;
import com.zh.util.dict.CodeMsg;
import com.zh.util.dict.RedisKey;
import com.zh.util.dict.Validator;
import com.zh.vo.Result;
import com.gargoylesoftware.htmlunit.TextPage;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

@RestController
@Validated
public class IndexController extends BaseController {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @Autowired
    private UserService userService;

    @RequestMapping("/")
    public String index() {
        return "hello zh";
    }

    @RequestMapping("/login")
    public Result login(@NotNull(message = "用户名不能为空")
                        @Pattern(regexp = Validator.REGEX_ACCOUNT, message = "用户名格式错误")
                                String account,
                        @NotNull(message = "密码不能为空")
                        @Pattern(regexp = Validator.REGEX_PASSWORD, message = "密码格式错误")
                                String password,
                        HttpSession session) {

        User user = userService.selectById(account);
        if (user == null) {
            return Result.failure(CodeMsg.ACCOUNT_OR_PASSWORD_ERROR);
        }

        if (!user.getPassword().equals(password)) {
            return Result.failure(CodeMsg.ACCOUNT_OR_PASSWORD_ERROR);
        }

        if (user.getStatus() != 1) {
            return Result.failure(CodeMsg.ACCOUNT_ERROR);
        }

        String token = CodecUtil.createUUID();

        //30天
        int exptime = 3600 * 24 * 30;

        session.setAttribute("token", token);
        redisTemplate.opsForValue().set(RedisKey.USER_TOKEN.getKey() + token, user, exptime, TimeUnit.SECONDS);
        return Result.success(token);
    }

    @RequestMapping("getToken")
    public Result getToken(HttpServletRequest request) {
        HttpSession session = request.getSession();
        String token = session.getAttribute("token").toString();
        return Result.success(redisTemplate.opsForValue().get(RedisKey.USER_TOKEN.getKey() + token));
    }

    @RequestMapping("/get")
    public JSONArray getDate(@NotNull(message = "周下标不能为空")
                             @Pattern(regexp = Validator.REGEX_ONLYNUM, message = "请输入数字下标")
                                     String index) {
        System.out.println("周下标:" + index);
        JSONArray arr = new JSONArray();
        for (int i = 0; i < 7; i++) {
            JSONObject mmp = new JSONObject();
            Date dd = new Date();
            Calendar c = new GregorianCalendar();
            c.setTime(dd);
            c.add(c.DATE, i - 2 + Integer.parseInt(index) * 7);//把日期往后增加一天.整数往后推,负数往前移动
            int year = c.get(Calendar.YEAR);//获取年份
            int month = c.get(Calendar.MONTH) + 1;//获取月份
            int day = c.get(Calendar.DATE);//获取日
            mmp.put("rq", year + "-" + (month < 10 ? "0" + month : month) + "-" + day);

            if (i == 0 || i == 6) {
                mmp.put("data", "");
            } else {
                int n = (int) (Math.random() * 10 + 1);
                System.out.println(n);
                JSONArray rcArr = new JSONArray();
                for (int y = 1; y < n; y++) {
                    int shour = (int) (Math.random() * 6 + 1) + 2;
                    int ehour = shour + 4;
                    String end = year + "-" + (month < 10 ? "0" + month : month) + "-" + day + " " + shour + ":00";
                    String start = year + "-" + (month < 10 ? "0" + month : month) + "-" + day + " " + ehour + ":00";
                    String title = "白茶清欢无别事,我在等风也等你!";
//                    String title = "白茶清欢无别事,我在等风也等你!";
                    String id = "152406344157788515528";
                    String textColor = "#FFF";
                    String allDay = "false";
                    JSONObject op = new JSONObject();
                    op.put("end", end);
                    op.put("start", start);
                    op.put("title", title);
                    op.put("color", getColor());
                    op.put("id", id);
                    op.put("textColor", textColor);
                    op.put("allDay", allDay);
                    rcArr.add(op);
                }
                mmp.put("data", rcArr);
            }
            arr.add(mmp);
        }
        System.out.println(arr);
        return arr;
    }

    public static String getColor() {
        //红色
        String red;
        //绿色
        String green;
        //蓝色
        String blue;
        //生成随机对象
        Random random = new Random();
        //生成红色颜色代码
        red = Integer.toHexString(random.nextInt(256)).toUpperCase();
        //生成绿色颜色代码
        green = Integer.toHexString(random.nextInt(256)).toUpperCase();
        //生成蓝色颜色代码
        blue = Integer.toHexString(random.nextInt(256)).toUpperCase();

        //判断红色代码的位数
        red = red.length() == 1 ? "0" + red : red;
        //判断绿色代码的位数
        green = green.length() == 1 ? "0" + green : green;
        //判断蓝色代码的位数
        blue = blue.length() == 1 ? "0" + blue : blue;
        //生成十六进制颜色值
        String color = "#" + red + green + blue;
        return color;
    }

    @RequestMapping("/getMessage")
    public String getMessage() {
        return "{\"ack_code\":\"SUCCESS\",\"data\":[{\"areaId\":\"440607\",\"deptId\":\"007049077\",\"depth\":\"1\",\"name\":\"佛山市三水区金融工作办公室\",\"orderId\":\"1\",\"parentId\":\"699711809\",\"shortName\":\"三水区金融办\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049480\",\"depth\":\"1\",\"name\":\"佛山市三水区总工会\",\"orderId\":\"1\",\"parentId\":\"00703991X\",\"shortName\":\"三水区总工会\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"092351907\",\"depth\":\"1\",\"name\":\"佛山市三水区食品药品监督管理局\",\"orderId\":\"1\",\"parentId\":\"708179923\",\"shortName\":\"三水区食品药品监督局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049675\",\"depth\":\"1\",\"name\":\"佛山市三水区国家税务局\",\"orderId\":\"027\",\"parentId\":\"007040195\",\"shortName\":\"三水区国税局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049288\",\"depth\":\"1\",\"name\":\"佛山市三水区质量技术监督局\",\"orderId\":\"028\",\"parentId\":\"007039848\",\"shortName\":\"三水区质监局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"726498784\",\"depth\":\"1\",\"name\":\"佛山市三水区市场监督管理局\",\"orderId\":\"1\",\"parentId\":\"007039776\",\"shortName\":\"三水区市场监督管理局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"557305776\",\"depth\":\"1\",\"name\":\"佛山市三水区发展规划和统计局\",\"orderId\":\"1\",\"parentId\":\"007039469,574510253,00703975X\",\"shortName\":\"三水区发规统局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049544\",\"depth\":\"1\",\"name\":\"佛山市三水区档案局\",\"orderId\":\"021\",\"parentId\":\"00703983X\",\"shortName\":\"三水区档案局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049392\",\"depth\":\"1\",\"name\":\"佛山市三水区环境保护局\",\"orderId\":\"1\",\"parentId\":\"007039821\",\"shortName\":\"三水区环保局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"595890195\",\"depth\":\"1\",\"name\":\"佛山市公共资源交易中心三水分中心\",\"orderId\":\"1\",\"parentId\":\"568266776\",\"shortName\":\"佛山市公共资源交易中心三水分中心\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"914406071\",\"depth\":\"1\",\"name\":\"佛山水业三水供水有限公司\",\"orderId\":\"1\",\"parentId\":\"566690872\",\"shortName\":\"三水供水公司\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"C03743173\",\"depth\":\"1\",\"name\":\"佛山市三水区残疾人联合会\",\"orderId\":\"1\",\"parentId\":\"456073806\",\"shortName\":\"三水区残联\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049333\",\"depth\":\"1\",\"name\":\"佛山市公安局三水分局\",\"orderId\":\"007\",\"parentId\":\"007039573\",\"shortName\":\"三水区公安分局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049165\",\"depth\":\"1\",\"name\":\"佛山市三水区人力资源和社会保障局\",\"orderId\":\"008\",\"parentId\":\"752878027,007039629\",\"shortName\":\"三水区人力资源社保局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"456094930\",\"depth\":\"1\",\"name\":\"佛山市三水区地方税务局\",\"orderId\":\"011\",\"parentId\":\"007039602,00704011X\",\"shortName\":\"三水区地税局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"557305565\",\"depth\":\"1\",\"name\":\"佛山市三水区经济和科技促进局\",\"orderId\":\"1\",\"parentId\":\"590098422,007039493,007039696,456072862\",\"shortName\":\"三水区经济和科技促进局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"728780265\",\"depth\":\"1\",\"name\":\"佛山市三水区公有资产管理办公室\",\"orderId\":\"020\",\"parentId\":\"765717978\",\"shortName\":\"三水区公资办\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"783850350\",\"depth\":\"1\",\"name\":\"佛山市三水区公安消防大队\",\"orderId\":\"022\",\"parentId\":\"007040216\",\"shortName\":\"三水区消防大队\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"K30389729\",\"depth\":\"1\",\"name\":\"中华人民共和国佛山海关驻三水办事处\",\"orderId\":\"024\",\"parentId\":\"007040187\",\"shortName\":\"佛山海关三水办事处\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"588317534\",\"depth\":\"1\",\"name\":\"三水区安全生产监督管理局\",\"orderId\":\"003\",\"parentId\":\"782021833,007039688\",\"shortName\":\"三水区安监局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049624\",\"depth\":\"1\",\"name\":\"佛山市三水区气象局\",\"orderId\":\"029\",\"parentId\":\"456073670\",\"shortName\":\"三水区气象局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"456094543\",\"depth\":\"1\",\"name\":\"广东省佛山市三水区烟草专卖局\",\"orderId\":\"030\",\"parentId\":\"708178381\",\"shortName\":\"三水区烟草专卖局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"557304933\",\"depth\":\"1\",\"name\":\"佛山市三水区市场监管局\",\"orderId\":\"031\",\"parentId\":\"007039717,007039733,007039987,590098422,708179923\",\"shortName\":\"三水区市场监管局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049819\",\"depth\":\"1\",\"name\":\"佛山市三水区委组织部（区机构编制委员会办公室）\",\"orderId\":\"012\",\"parentId\":\"752878027,007039629\",\"shortName\":\"三水区委组织部（区编委办）\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049018\",\"depth\":\"1\",\"name\":\"佛山市三水区财政局\",\"orderId\":\"010\",\"parentId\":\"007039602,00704011X\",\"shortName\":\"三水区财政局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"456093188\",\"depth\":\"1\",\"name\":\"佛山市三水区社会保险基金管理局\",\"orderId\":\"013\",\"parentId\":\"456073291,007039629\",\"shortName\":\"三水区社保局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"557305733\",\"depth\":\"1\",\"name\":\"佛山市三水区交通运输和城市管理局\",\"orderId\":\"1\",\"parentId\":\"574466125,007039821,574510253,699764863\",\"shortName\":\"三水区交通运输城管局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"456093241\",\"depth\":\"1\",\"name\":\"佛山市三水区公路局\",\"orderId\":\"1\",\"parentId\":\"699764863,456072782\",\"shortName\":\"三水区公路局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"576426899\",\"depth\":\"1\",\"name\":\"佛山市三水区农林渔业局\",\"orderId\":\"017\",\"parentId\":\"007039987\",\"shortName\":\"三水区农林渔业局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"075700001\",\"depth\":\"1\",\"name\":\"佛山市三水区文体旅游局\",\"orderId\":\"018\",\"parentId\":\"007040195,007039717,007039733,007039899\",\"shortName\":\"三水区文体旅游局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"557305602\",\"depth\":\"1\",\"name\":\"佛山市三水区国土城建和水务局\",\"orderId\":\"1\",\"parentId\":\"574466125,007039653,007039987,007039821,007040021,007040064,574510253,699764863\",\"shortName\":\"三水区国土城建水务局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"557304896\",\"depth\":\"1\",\"name\":\"佛山市三水区卫生和计划生育局\",\"orderId\":\"1\",\"parentId\":\"091760215,782021833,708179923\",\"shortName\":\"三水区卫生和计划生育局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007048963\",\"depth\":\"1\",\"name\":\"中共佛山市三水区委政法委员会（区司法局）\",\"orderId\":\"369\",\"parentId\":\"007039581\",\"shortName\":\"三水区委政法委\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"773066407\",\"depth\":\"1\",\"name\":\"三水区审改办\",\"orderId\":\"370\",\"parentId\":\"\",\"shortName\":\"三水区审改办\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"590066623\",\"depth\":\"1\",\"name\":\"佛山市三水区政务监察和审计局\",\"orderId\":\"023\",\"parentId\":\"\",\"shortName\":\"三水区政监局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"G18588654\",\"depth\":\"1\",\"name\":\"中华人民共和国佛山三水海事处\",\"orderId\":\"025\",\"parentId\":\"72596099X\",\"shortName\":\"三水海事处\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"007049093\",\"depth\":\"1\",\"name\":\"佛山市三水区教育局\",\"orderId\":\"005\",\"parentId\":\"007039485\",\"shortName\":\"三水区教育局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"557305637\",\"depth\":\"1\",\"name\":\"中共佛山市三水区委统一战线工作部（佛山市三水区外事侨务局）\",\"orderId\":\"1\",\"parentId\":\"742958402,456073806,007040283,007039565\",\"shortName\":\"三水区委统战部（区外侨局）\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"315228974\",\"depth\":\"1\",\"name\":\"佛山市三水区民政局\",\"orderId\":\"1\",\"parentId\":\"007039565,456073806\",\"shortName\":\"三水区民政局\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"592191073\",\"depth\":\"1\",\"name\":\"三水公证处\",\"orderId\":\"1\",\"parentId\":\"007039581\",\"shortName\":\"三水公证处\",\"status\":\"1\"},{\"areaId\":\"440607\",\"deptId\":\"440683000016206\",\"depth\":\"1\",\"name\":\"广东电网有限责任公司佛山三水供电局\",\"orderId\":\"1\",\"parentId\":\"73757157X\",\"shortName\":\"三水供电局\",\"status\":\"1\"}],\"errors\":[]}";
    }

    @RequestMapping("/getPf")
    public String getPf() {
        JSONObject mmp = new JSONObject();
        List list = new ArrayList();
        for (int i = 0; i < 15; i++) {
            JSONObject m = new JSONObject();
            m.put("ability", (int) (Math.random() * 5 + 1));
            m.put("ability2", 5 - Integer.parseInt(m.get("ability").toString()));

            m.put("attitude", (int) (Math.random() * 5 + 1));
            m.put("attitude2", 5 - Integer.parseInt(m.get("attitude").toString()));

            m.put("service", (int) (Math.random() * 5 + 1));
            m.put("service2", 5 - Integer.parseInt(m.get("service").toString()));

            m.put("time", (int) (Math.random() * 5 + 1));
            m.put("time2", 5 - Integer.parseInt(m.get("time").toString()));

            m.put("cost", "¥ " + (int) (Math.random() * 10000 + 1) + 1);
            m.put("id", "10522121" + i);
            m.put("address", "解放路" + i * 21 + "号");
            m.put("tel", "188*******666");
            m.put("name", "*****包子铺");
            m.put("content", "检查卫生");

            list.add(m);
        }
        mmp.put("total", list.size());
        mmp.put("rows", list);
        return mmp.toJSONString();
    }

    @RequestMapping(value = "/gouploadimg", method = RequestMethod.GET)
    public String goUploadImg() {
        //跳转到 templates 目录下的 uploadimg.html
        return "uploadimg";
    }

    //处理文件上传
    @RequestMapping(value = "/upimg", method = RequestMethod.POST)
    public
    @ResponseBody
    String uploadImg(@RequestParam("file") MultipartFile file,
                     HttpServletRequest request) {
        String contentType = file.getContentType();

        String fileName = file.getOriginalFilename();
        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
        fileName = UUID.randomUUID().toString().replaceAll("-", "") + "." + suffix;
        String filePath = "D:\\upimg\\";
        try {
            FileUtil.uploadFile(file.getBytes(), filePath, fileName);
            UpImg e = new UpImg();
            e.setName(fileName);
            e.setUrl(filePath);
            e.setCreator("上传用户");
            Date nowdate = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            e.getCreattime(sdf.format(nowdate));
            e.setSize(file.getSize() + "");
            e.setType("照片");
            upImgService.insert(e);
            System.out.print("上传文件成功---->" + e.toString());
        } catch (Exception e) {
            // TODO: handle exception
        }
        //返回json
        return "{\"flag\": 1}";
    }

    @Autowired
    UpImgService upImgService;

    @RequestMapping("/imgList")
    public Result imgList() {
        List<UpImg> list = upImgService.selectList(new EntityWrapper<UpImg>());

        return Result.success(list);
    }

    @RequestMapping("/getMytask")
    public String getMytask() {
        JSONObject mmp = new JSONObject();
        List list = new ArrayList();
        for (int i = 0; i < 15; i++) {
            JSONObject m = new JSONObject();

            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date());
            String nd = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DATE);
            String ed = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + (cal.get(Calendar.DATE) + 2);
            m.put("id", cal.getTime());
            m.put("creattime", nd);
            m.put("endTime", ed);
            m.put("startTime", nd);
            m.put("jgObj", "监管对象" + Math.ceil(Math.random() * 100 + 1));
            m.put("scope", "所属区域" + Math.ceil(Math.random() * 100 + 1));
            m.put("address", "地址" + Math.ceil(Math.random() * 100 + 1));
            m.put("state", "任务状态" + Math.ceil(Math.random() * 100 + 1));
            m.put("street", "所属街道" + Math.ceil(Math.random() * 100 + 1));
            m.put("money", Math.ceil(Math.random() * 100 + 1));
            list.add(m);
        }
        mmp.put("rows", list);
        mmp.put("total", list.size());
        return mmp.toString();
    }

    @RequestMapping("/getTimeAxis")
    public String getTimeAxis() {
        JSONObject mmp = new JSONObject();
        List list = new ArrayList();
        String[] matter = {"已领取", "已执行", "已初审", "已复核", "已报账", "已划款"};

        for (int i = 0; i < 6; i++) {
            JSONObject m = new JSONObject();
            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date());
            String nd = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DATE) + " "
                    + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE);
            m.put("id", i);
            m.put("matter", matter[i]);
            m.put("agent", "小猪佩奇");
            m.put("time", nd);
            list.add(m);
        }
        mmp.put("rows", list);
        mmp.put("total", list.size());
        return mmp.toString();
    }

    @RequestMapping("/getMoneyCount")
    public String getMoneyCount() {
        JSONObject mmp = new JSONObject();
        List xList = new ArrayList();
        List yList = new ArrayList();

        for (int i = 0; i < 10; i++) {
            xList.add(i);
            yList.add(((int) (Math.ceil(Math.random() * 200))));
        }
        mmp.put("xList", xList);
        mmp.put("yList", yList);
        mmp.put("today", (int) (Math.ceil(Math.random() * 200)));
        mmp.put("total", (int) (Math.ceil(Math.random() * 200)) * 100);
        mmp.put("ranking", (int) (Math.ceil(Math.random() * 100)));

        return mmp.toString();
    }

    @RequestMapping("/getCompleteCount")
    public String getCompleteCount() {
        JSONObject mmp = new JSONObject();
        List xList = new ArrayList();
        List yList = new ArrayList();

        for (int i = 0; i < 10; i++) {
            xList.add(i);
            yList.add(((int) (Math.ceil(Math.random() * 10))));
        }
        mmp.put("xList", xList);
        mmp.put("yList", yList);
        mmp.put("today", (int) (Math.ceil(Math.random() * 10)));
        mmp.put("total", (int) (Math.ceil(Math.random() * 8)) * 100);
        mmp.put("ranking", (int) (Math.ceil(Math.random() * 165)));

        return mmp.toString();
    }

    @RequestMapping("/getInvalidCount")
    public String getInvalidCount() {
        JSONObject mmp = new JSONObject();
        List xList = new ArrayList();
        List yList = new ArrayList();

        for (int i = 0; i < 10; i++) {
            xList.add(i);
            yList.add(((int) (Math.ceil(Math.random() * 4 - 1))));
        }
        mmp.put("xList", xList);
        mmp.put("yList", yList);
        mmp.put("today", (int) (Math.ceil(Math.random() * 3)) - 1);
        mmp.put("total", (int) (Math.ceil(Math.random() * 3)) * 100);
        mmp.put("ranking", (int) (Math.ceil(Math.random() * 100)));

        return mmp.toString();
    }

    @RequestMapping("/getRatioCount")
    public String getRatioCount() {
        JSONObject mmp = new JSONObject();
        List xList = new ArrayList();
        List yList = new ArrayList();

        for (int i = 0; i < 10; i++) {
            xList.add(i);
            yList.add(((int) (Math.ceil(Math.random() * 3 - 1))));
        }
        mmp.put("xList", xList);
        mmp.put("yList", yList);
        mmp.put("today", (int) (Math.ceil(Math.random() * 3) - 1));
        mmp.put("total", (int) (Math.ceil(Math.random() * 2)) * 100);
        mmp.put("ranking", (int) (Math.ceil(Math.random() * 100)));

        return mmp.toString();
    }

    @RequestMapping("/getBingCount")
    public String getBingCount() {
        List list = new ArrayList();

        String[] names = {"无效任务", "已完成任务", "进行中任务"};
        String[] colors = {"#FF6666", "#33ff66", "#3366ff"};
        for (int i = 0; i < names.length; i++) {
            JSONObject m = new JSONObject();
            m.put("name", names[i]);
            m.put("data", (i == 1 ? Math.ceil(Math.random() * 200) : Math.ceil(Math.random() * 50)));
            m.put("color", colors[i]);
            list.add(m);
        }

        System.out.print(list.toString());
        return list.toString();
    }

    @RequestMapping("/getYearCount")
    public String getYearCount() {
        JSONObject mmp = new JSONObject();
        List xAxis = new ArrayList();
        List ywcList = new ArrayList();
        List wxList = new ArrayList();

        for (int i = 1; i < 13; i++) {
            xAxis.add(i + "月");
            ywcList.add(Math.ceil(Math.random() * 30));
            wxList.add(Math.ceil(Math.random() * 5));
        }
        mmp.put("xAxis", xAxis);
        mmp.put("ywcList", ywcList);
        mmp.put("wxList", wxList);
        return mmp.toString();
    }

    @RequestMapping("/getEwmData")
    public String getEwmData() throws IOException {
        String URL = "http://1.ego360.cn:9000/Home/scanresult?billcode=BW8802418073110006";
        WebClient wc = new WebClient();
        wc.getOptions().setJavaScriptEnabled(true); // 启用JS解释器，默认为true
        wc.getOptions().setCssEnabled(false); // 禁用css支持
        wc.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时，是否抛出异常
        wc.getOptions().setTimeout(10000); // 设置连接超时时间 ，这里是10S。如果为0，则无限期等待
        HtmlPage htmlPage = wc.getPage(URL);
        String pageXml = htmlPage.asXml(); // 以xml的形式获取响应文本
        Document doc = Jsoup.parse(pageXml);
        Elements el = doc.select(".tbOneMain tr");
        Elements e2 = doc.select(".mianListTd");
        e2.text();
        List list = new ArrayList();
        for (Element e : el) {
            JSONObject m = new JSONObject();

            for (Element x : e.select("td")) {
                if (x.toString().indexOf("left") > -1) {
                    m.put("value", x.text().toString());
                } else {
                    m.put("label", x.text().toString());
                }
            }

            list.add(m);
        }

        System.out.println("e2---->" + e2.text());
        return e2.toString();
    }

    @RequestMapping("/getCy")
    public String getCy() {
        JSONObject mmp = new JSONObject();
        List list = new ArrayList();
        for (int i = 0; i < 100; i++) {
            JSONObject m = new JSONObject();
            Date dd = new Date();
            Calendar c = new GregorianCalendar();
            c.setTime(dd);
            int year = c.get(Calendar.YEAR);//获取年份
            int month = c.get(Calendar.MONTH) + 1;//获取月份
            int day = c.get(Calendar.DATE);//获取日
            int HOUR = c.get(Calendar.HOUR);//获取日
            int MINUTE = c.get(Calendar.MINUTE);//获取日
            int SECOND = c.get(Calendar.SECOND);//获取日
            m.put("time", year + "-" + (month < 10 ? "0" + month : month) + "-" + day + " " + HOUR + ":" + MINUTE + ":" + SECOND);
            m.put("name", "猪肉" + i);
            m.put("type", "病菌" + i);
            int hg = (int) Math.ceil(Math.random() * 2);
            m.put("hg", hg == 1 ? "合格" : "不合格");
            list.add(m);
        }

        mmp.put("rows", list);
        mmp.put("total", list.size());
        return mmp.toString();
    }

    @RequestMapping("/getDkList")
    public String getDkList(String depart,int rows, int page) throws IOException {
        String url = "https://www.forsunder.com/sssy/sssyxt/SsMngCompanyInfo!getCompanyByMark?scope="+depart+"&rows=" +
                rows + "&page=" + page;
        System.out.println("rows-------------------------->" + rows);
        System.out.println("page-------------------------->" + page);
        System.out.println("url-------------------------->" + url);
        WebClient wc = new WebClient();
        wc.getOptions().setJavaScriptEnabled(true); // 启用JS解释器，默认为true
        wc.getOptions().setCssEnabled(false); // 禁用css支持
        wc.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时，是否抛出异常
        wc.getOptions().setTimeout(10000); // 设置连接超时时间 ，这里是10S。如果为0，则无限期等待
        HtmlPage htmlPage = null;
        TextPage textPage;
        textPage = wc.getPage(url);
        System.out.println("page-------------------------->" + textPage.getContent().toString());
//        return textPage.getContent().toString();
        return textPage.getContent().toString();
    }

    @RequestMapping("/getDkForId")
    public String getDkForId(String comcode, int page, int rows) throws IOException {
        String url = "https://www.forsunder.com/sssy/sssyxt/traceTrade!getPurchaseRecord?purchaserId=" + comcode + "&page=" + page + "&rows=" + rows;
        System.out.println("url-------------------------->" + url);
        WebClient wc = new WebClient();
        wc.getOptions().setJavaScriptEnabled(true); // 启用JS解释器，默认为true
        wc.getOptions().setCssEnabled(false); // 禁用css支持
        wc.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时，是否抛出异常
        wc.getOptions().setTimeout(10000); // 设置连接超时时间 ，这里是10S。如果为0，则无限期等待
        HtmlPage htmlPage = null;
        TextPage textPage;
        textPage = wc.getPage(url);

        return textPage.getContent().toString();
    }

    @RequestMapping("/getCjList")
    public String getCjList(String depart, int page, int rows) throws IOException {
        Date date = new Date();//取时间
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = new GregorianCalendar();
        String sd = formatter.format(calendar.getTime());
        calendar.setTime(date);
        calendar.add(calendar.DATE, 1);//把日期往后增加一天.整数往后推,负数往前移动

        String ed = formatter.format(calendar.getTime());
        System.out.println("sd-------------" + sd);
        System.out.println("ed-------------" + ed);
        System.out.println("depart-------------" + depart);

        String url = "http://ssfso.ss.gov.cn:8001/sscjxt/SsMobileSampleInfo!showJsonDatagridListByPage.action?" +
                "year=" + sd + "&month=" + ed + "&depart=" + depart + "&rows=" + rows + "&page=" + page;
        System.out.println("url-------------" + url);
        WebClient wc = new WebClient();
        wc.getOptions().setJavaScriptEnabled(true); // 启用JS解释器，默认为true
        wc.getOptions().setCssEnabled(false); // 禁用css支持
        wc.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时，是否抛出异常
        wc.getOptions().setTimeout(10000); // 设置连接超时时间 ，这里是10S。如果为0，则无限期等待
        HtmlPage htmlPage = null;
        TextPage textPage;
        textPage = wc.getPage(url);

        return textPage.getContent().toString();

    }

}